package com.iwhalecloud.bss.kite.cucc.web.service.accept.handler.module;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.Optional;
import java.util.concurrent.atomic.AtomicBoolean;
import java.util.stream.Collectors;

import com.iwhalecloud.bss.kite.common.constant.KeyConsts;
import com.iwhalecloud.bss.kite.cucc.common.constant.LocalKeyConsts;
import com.iwhalecloud.bss.kite.cucc.service.util.ProdCateUtil;
import com.iwhalecloud.bss.kite.cucc.spec.impl.transfer.GoodsInfoTransfer;
import com.iwhalecloud.bss.kite.dataservice.cache.OfferCache;
import com.iwhalecloud.bss.kite.dataservice.entity.spec.Offer;
import com.iwhalecloud.bss.kite.manager.api.IOperateSceneInstService;
import com.iwhalecloud.bss.kite.manager.inst.KiteSceneInst;
import com.iwhalecloud.bss.kite.service.scene.attr.OperateInstAttrService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.iwhalecloud.bss.kite.client.vo.scene.ProdAttrModuleVO;
import com.iwhalecloud.bss.kite.client.vo.scene.ProdAttrVO;
import com.iwhalecloud.bss.kite.client.vo.scene.ProdRoleModuleVO;
import com.iwhalecloud.bss.kite.client.vo.scene.ProductModuleVO;
import com.iwhalecloud.bss.kite.common.constant.SymbolConsts;
import com.iwhalecloud.bss.kite.common.util.KiteBeanUtils;
import com.iwhalecloud.bss.kite.common.util.KiteListUtils;
import com.iwhalecloud.bss.kite.common.util.KiteObjectUtils;
import com.iwhalecloud.bss.kite.common.util.KiteStringUtils;
import com.iwhalecloud.bss.kite.cucc.client.api.attr.IUnicomRegionService;
import com.iwhalecloud.bss.kite.cucc.client.api.order.IBusinessChangeService;
import com.iwhalecloud.bss.kite.cucc.client.dto.attr.UnicomRegion;
import com.iwhalecloud.bss.kite.cucc.client.vo.scene.CuccProdAttrVO;
import com.iwhalecloud.bss.kite.cucc.client.vo.scene.GoodsModifyInfoVO;
import com.iwhalecloud.bss.kite.cucc.client.vo.scene.OptionalAdditionalOfferModuleVO;
import com.iwhalecloud.bss.kite.cucc.client.vo.scene.SceneNewOfferSeneVO;
import com.iwhalecloud.bss.kite.cucc.service.pos.handler.CuccPosServiceUtils;
import com.iwhalecloud.bss.kite.dataservice.cache.DcPublicCache;
import com.iwhalecloud.bss.kite.dataservice.entity.DcPublic;
import com.iwhalecloud.bss.kite.manager.api.IQuerySceneInstService;
import com.iwhalecloud.bss.kite.manager.inst.KiteAttr;
import com.iwhalecloud.bss.kite.manager.inst.KiteOfferInst;
import com.iwhalecloud.bss.kite.manager.inst.KiteProdInst;
import com.iwhalecloud.bss.kite.web.context.KiteWebContext;
import com.iwhalecloud.bss.kite.web.service.accept.bo.AcceptContext;
import com.iwhalecloud.bss.kite.web.service.accept.bo.SceneModule;
import com.ztesoft.bss.base.entity.StaticAttrDO;
import com.ztesoft.bss.common.util.SpringUtil;
import com.ztesoft.bss.svcability.util.ListUtil;

/**
 * @author wei.yanhong
 * @ClassName: ModifyInfoModuleHandler
 * @Description: 业务变更模块数据组装初始化等
 * @date 2020/9/16
 */
@Service
public class ModifyInfoModuleHandler extends LocalAbstractProductModuleHandler {

    @Autowired
    private IQuerySceneInstService querySceneInstService;

    @Autowired
    private IBusinessChangeService businessChangeService;

    @Autowired
    private IUnicomRegionService unicomRegionService;

    @Autowired
    private IOperateSceneInstService operateSceneInstService;

    private static final String RATESCHANGE_SERVICCEOFFER = "1009"; //资费变更业务

    @Override
    public List<GoodsModifyInfoVO> execute(AcceptContext context, SceneModule sceneModule) {
        String sceneInstId = context.getSceneVo().getSceneInstId();
        String custId = context.getAcceptRequest().getCustId();
        //获取所有的操作类型
        SceneNewOfferSeneVO sceneNewOfferSeneVO = (SceneNewOfferSeneVO) context.getSceneVo();

        GoodsModifyInfoVO modifyInfo = getProductChangeInfo(custId, sceneInstId, false);
        if (KiteListUtils.isNotEmpty(modifyInfo.getProduct())) {
            dealGroupAttrs(modifyInfo.getProduct());
            divideProdAttr(modifyInfo.getProduct(), context.getAcceptRequest().getSceneInstId(),
                context.getAcceptRequest().getCustId(), false);
        }

        sceneNewOfferSeneVO.setGoodsModifyInfo(modifyInfo);
        return Collections.singletonList(modifyInfo);
    }

    @Override
    public List<GoodsModifyInfoVO> previewSceneVo(AcceptContext context, SceneModule sceneModule) {

        String sceneInstId = context.getSceneVo().getSceneInstId();
        String custId = context.getAcceptRequest().getCustId();
        //获取所有的操作类型
        GoodsModifyInfoVO modifyInfo = getProductChangeInfo(custId, sceneInstId, true);
        List<String> serviceOfferIdList = querySceneInstService.getExtParameterValue(sceneInstId, "BUSI_CHANGE_SERVICEOFFERID");

        if (KiteListUtils.isNotEmpty(modifyInfo.getProduct())) {
            modifyInfo.getProduct().forEach(productModule ->{
                productModule.getProdRole().forEach(prodRole ->{
                    List<ProdAttrVO> cuccProdAttrList = new ArrayList<>();
                    if (KiteListUtils.isEmpty(prodRole.getProdAttr().getProdAttrList())) {
                        return;
                    }

                    //将属性设置为预览模式，并设置变动标识
                    prodRole.getProdAttr().getProdAttrList().forEach((attr) -> {
                        CuccProdAttrVO cuccProdAttrVO = new CuccProdAttrVO();
                        KiteBeanUtils.copyProperties(attr, cuccProdAttrVO);
                        KiteAttr kiteAttr = querySceneInstService.getProdInstAttr(custId, prodRole.getProdInstId(), attr.getFieldName());
                        if (!KiteStringUtils.isEqual(kiteAttr.getValue(), kiteAttr.getOriginValue())) {
                            cuccProdAttrVO.setNewValue(kiteAttr.getValue());
                            cuccProdAttrVO.setChangeFlag(true);
                            cuccProdAttrVO.setOldValue(kiteAttr.getOriginValue());
                            if (KiteStringUtils.equalsAny(kiteAttr.getFieldName(), "2_0000209","2_0000105")) {
                                String[] regionCodes = KiteStringUtils.split(kiteAttr.getOriginValue(), SymbolConsts.COMMA);
                                List<String> regionNames = Arrays.stream(regionCodes).map(s -> {
                                    UnicomRegion region = unicomRegionService.getRegion(s);
                                    return Objects.nonNull(region) ? region.getRegionName() : "";
                                }).collect(Collectors.toList());
                                cuccProdAttrVO.setOldValueDesc(KiteStringUtils.join(regionNames, SymbolConsts.HYPHEN));
                            }
                            else {
                                String oldValueDesc = Optional.ofNullable(cuccProdAttrVO.getAttrValues().stream().filter(staticAttr -> staticAttr.getAttrValue().equals(cuccProdAttrVO.getOldValue())).findFirst().orElseGet(StaticAttrDO::new).getAttrValueDesc()).orElseGet(String::new);
                                cuccProdAttrVO.setOldValueDesc(oldValueDesc);
                            }
                        }else{
                            String rootInstId = querySceneInstService.getSceneInst(sceneInstId).getRootInstId();
                            String categoryId = querySceneInstService.getOfferInstAttrValue(custId, rootInstId, "cateId");
//预览的时候如果属性值没有变更，则不传bizType
                            if (KiteListUtils.isNotEmpty(serviceOfferIdList) && serviceOfferIdList.size() > 1) {
                                //精品网产品变更AZ端口类型特殊处理

                                serviceOfferIdList.removeIf(serviceOfferId->{
                                    AtomicBoolean haven = new AtomicBoolean(false);
                                    List<DcPublic> dcPublics = DcPublicCache.getByPcode("2022040616", categoryId,serviceOfferId);
                                    if(null!=dcPublics&&dcPublics.size()>0){
                                        dcPublics.forEach(dc->{
                                            if(dc.getCodea().contains(kiteAttr.getFieldName())){
                                                haven.set(true);
                                            };
                                        });
                                    }
                                    return haven.get();
                                });
                            }

                        }
                        cuccProdAttrVO.setAttrValueTypeId("TT");
                        cuccProdAttrList.add(cuccProdAttrVO);
                    });
                    cuccProdAttrList.removeIf(attr -> KeyConsts.PROD_ATTR_SHOW_TYPE_H.equals(attr.getShowType()) || KeyConsts.PROD_ATTR_SHOW_TYPE_E.equals(attr.getShowType()));
                    prodRole.getProdAttr().setProdAttrList(cuccProdAttrList);
                });
            });
            operateSceneInstService.putExtParameter(sceneInstId, "BUSI_CHANGE_SERVICEOFFERID",
                serviceOfferIdList); //将serviceOfferIdList放入场景中，便于在操作类型预览组件中获取
        }
        SceneNewOfferSeneVO sceneNewOfferSeneVO = (SceneNewOfferSeneVO) context.getSceneVo();
        modifyInfo.setIsEdit("F");
        if (KiteListUtils.isNotEmpty(modifyInfo.getProduct())) {
            dealGroupAttrs(modifyInfo.getProduct());
            divideProdAttr(modifyInfo.getProduct(), context.getAcceptRequest().getSceneInstId(),
                context.getAcceptRequest().getCustId(), true);
        }

        sceneNewOfferSeneVO.setGoodsModifyInfo(modifyInfo);
        return Collections.singletonList(modifyInfo);
    }

    public GoodsModifyInfoVO getProductChangeInfo(String custId, String sceneInstId, boolean isPreview) {
        GoodsModifyInfoVO modifyInfo = new GoodsModifyInfoVO();
        List<ProductModuleVO> productModule = new ArrayList<>(); //产品信息
        List<String> serviceOfferIdList = querySceneInstService.getExtParameterValue(sceneInstId, "BUSI_CHANGE_SERVICEOFFERID");//获取页面勾选的操作类型
        List<KiteProdInst> kiteProdInsts = querySceneInstService.listProdInsts(sceneInstId);
        // 如果当前只勾选资费变更,则业务变更模块只返回商品信息和资费变更信息
        boolean ratesChangeFlag = false;
        if (KiteListUtils.isNotEmpty(serviceOfferIdList) && serviceOfferIdList.size() == 1 && serviceOfferIdList
            .contains(RATESCHANGE_SERVICCEOFFER)) {
            ratesChangeFlag = true;
        }



        if (KiteListUtils.isNotEmpty(kiteProdInsts) && !ratesChangeFlag) {
            kiteProdInsts.forEach(kiteProdInst -> {
            	//融合框架商品的业务产品不在这里返回
                KiteOfferInst offerInst = querySceneInstService.getMainOfferInstByProdInstId(custId, kiteProdInst.getProdInstId());
                if (!KiteObjectUtils.isEmpty(offerInst)&&!GoodsInfoTransfer.isAddRoleOffer(offerInst.getSpecId(),Optional.ofNullable(OfferCache.get(offerInst.getSpecId())).map(Offer::getCateId).orElse(""))) {
                    ProductModuleVO productModuleVO = businessChangeService.genProductVO(kiteProdInst.getProdId());
                    ProdRoleModuleVO prodRoleVO = businessChangeService.genProductRoleVO(kiteProdInst);
                    ProdAttrModuleVO prodAttrModule = new ProdAttrModuleVO();
                    List<ProdAttrVO> prodAttrList = new ArrayList();
                    if (KiteListUtils.isNotEmpty(serviceOfferIdList)) {
                        for (String serviceOfferId : serviceOfferIdList) {
                            prodAttrModule = businessChangeService
                                .dealProdAttrList(sceneInstId, custId, kiteProdInst, serviceOfferId, prodAttrModule);

                            if (KiteListUtils.isNotEmpty(prodAttrModule.getProdAttrList())) {
                                prodAttrList.addAll(prodAttrModule.getProdAttrList());
                            }
                        }
                        List<ProdAttrVO> prodAttrVOList = businessChangeService.removeProdAttrVO(prodAttrList); // 过滤去重
                        // 资料修正单部分属性必填、是否可编辑处理
                        boolean flag = (KiteListUtils.isNotEmpty(serviceOfferIdList) && serviceOfferIdList.contains("1080"));
                        prodAttrVOList.removeIf(attr -> KeyConsts.PROD_ATTR_SHOW_TYPE_H.equals(attr.getShowType()) || KeyConsts.PROD_ATTR_SHOW_TYPE_E.equals(attr.getShowType()));
                        prodAttrModule.setProdAttrList(this.prodAttrConfig(sceneInstId, prodAttrVOList, flag));
                    } else {
                        // 通过bizType获取操作类型
                            String serviceOfferIdListNew = querySceneInstService //通过bizType获取页面勾选的操作类型
                                .getExtParameterValue(sceneInstId, "bizType");
                            if(KiteStringUtils.isNotEmpty(serviceOfferIdListNew)){
                                List<String> operateTypeList= Arrays.asList(KiteStringUtils.split(serviceOfferIdListNew,","));
                                for (String serviceOfferId : operateTypeList) {
                                    prodAttrModule = businessChangeService
                                        .dealProdAttrList(sceneInstId, custId, kiteProdInst, serviceOfferId, prodAttrModule);

                                    if (KiteListUtils.isNotEmpty(prodAttrModule.getProdAttrList())) {
                                        prodAttrList.addAll(prodAttrModule.getProdAttrList());
                                    }
                                }
                            }

                        List<ProdAttrVO> prodAttrVOList = businessChangeService.removeProdAttrVO(prodAttrList); // 过滤去重
                        prodAttrVOList.removeIf(attr -> KeyConsts.PROD_ATTR_SHOW_TYPE_H.equals(attr.getShowType()) || KeyConsts.PROD_ATTR_SHOW_TYPE_E.equals(attr.getShowType()));
                        prodAttrModule.setProdAttrList(this.prodAttrConfig(sceneInstId, prodAttrVOList, false));
                    }

                    prodRoleVO.setProdAttr(prodAttrModule);
                    productModuleVO.getProdRole().add(prodRoleVO);

                    productModule.add(productModuleVO);
                }
            });
            modifyInfo.setProduct(productModule);
        }




        if (ratesChangeFlag || (KiteListUtils.isNotEmpty(serviceOfferIdList) &&
           (serviceOfferIdList.contains(RATESCHANGE_SERVICCEOFFER) || serviceOfferIdList.contains("1080") || serviceOfferIdList.contains("1091")))) {
           if(serviceOfferIdList.contains("1091")){
               operateSceneInstService.putExtParameter(sceneInstId, "PAY_TIAOSU_FLAG","T");
           }
            OptionalAdditionalOfferModuleHandler handler = SpringUtil.getBean(OptionalAdditionalOfferModuleHandler.class);
            Map<String, OptionalAdditionalOfferModuleVO> additionalOffers = handler.getOptionalAdditionalOfferModuleVO(sceneInstId, isPreview);
            if (Objects.nonNull(additionalOffers)) {
                modifyInfo.setAdditionalOffers(additionalOffers);
            }
           if(serviceOfferIdList.contains("1091")){
               operateSceneInstService.removeExtParameter(sceneInstId, "PAY_TIAOSU_FLAG");
           }
        }
        this.specialProcessForBusiRemark(sceneInstId, modifyInfo, serviceOfferIdList);
        return modifyInfo;
    }

    /**
     * 针对上海五大双线产品所有的业务变更，勾选任一业务变更子类型，均可以修改“业务需求说明”字段
     * @param sceneInstId
     * @param modifyInfo
     * @param serviceOfferIdList
     */
    private void specialProcessForBusiRemark(String sceneInstId, GoodsModifyInfoVO modifyInfo, List<String> serviceOfferIdList) {
        if (KiteListUtils.isEmpty(serviceOfferIdList)) {
            return;
        }
        KiteSceneInst sceneInst = querySceneInstService.getSceneInst(sceneInstId);
        if (!LocalKeyConsts.PROVINCE_SHANGHAI.equals(sceneInst.getProvinceNbr())) {
            return;
        }
        String rootInstId = querySceneInstService.getSceneInst(sceneInstId).getRootInstId();
        String cateId = querySceneInstService.getOfferInstAttrValue(sceneInst.getCustId(), rootInstId, "cateId");
        if(!KiteStringUtils.equalsAny(cateId, ProdCateUtil.getDoubleLineCateIdForArr())) {
            return;
        }
        List<KiteProdInst> kiteProdInsts = querySceneInstService.listProdInsts(sceneInstId);
        List<ProductModuleVO> productModule = Optional.ofNullable(modifyInfo.getProduct()).orElse(new ArrayList<>());
        // 为空意味着是只勾选了资费变更的,最后要把product节点对象设置上。不为空的时候遍历属性,不存在就加上
        if (KiteListUtils.isEmpty(productModule)) {
            kiteProdInsts.forEach(kiteProdInst -> {
                List<ProdAttrVO> prodAttrList = new ArrayList<>();
                this.addBusinessRemarkAttr(sceneInstId, prodAttrList, serviceOfferIdList, kiteProdInst);
                if (!prodAttrList.isEmpty()) {
                    ProductModuleVO productModuleVO = businessChangeService.genProductVO(kiteProdInst.getProdId());
                    ProdRoleModuleVO prodRoleVO = businessChangeService.genProductRoleVO(kiteProdInst);
                    ProdAttrModuleVO prodAttrModule = new ProdAttrModuleVO();

                    prodAttrModule.setProdAttrList(prodAttrList);
                    prodRoleVO.setProdAttr(prodAttrModule);
                    productModuleVO.getProdRole().add(prodRoleVO);
                    productModule.add(productModuleVO);
                }
            });
            modifyInfo.setProduct(productModule);
        }
        else {
            productModule.forEach(productVo -> {
                productVo.getProdRole().forEach(roleVo -> {
                    KiteProdInst prodInst = querySceneInstService.getProdInst(sceneInst.getCustId(), roleVo.getProdInstId());
                    roleVo.getProdAttr().setProdAttrList(this.addBusinessRemarkAttr(sceneInstId, roleVo.getProdAttr().getProdAttrList(), serviceOfferIdList, prodInst));
                });
            });
        }
    }

    public List<ProdAttrVO> addBusinessRemarkAttr(String sceneInstId, List<ProdAttrVO> prodAttrVOList, List<String> serviceOfferIdList, KiteProdInst kiteProdInst) {
        // 没有勾选子变更类型的不需要处理
        if (KiteListUtils.isEmpty(serviceOfferIdList)) {
            return prodAttrVOList;
        }
        // 非上海五大双线的不处理
        KiteSceneInst sceneInst = querySceneInstService.getSceneInst(sceneInstId);
        if (!LocalKeyConsts.PROVINCE_SHANGHAI.equals(sceneInst.getProvinceNbr())) {
            return prodAttrVOList;
        }
        String rootInstId = querySceneInstService.getSceneInst(sceneInstId).getRootInstId();
        String cateId = querySceneInstService.getOfferInstAttrValue(sceneInst.getCustId(), rootInstId, "cateId");
        if(!KiteStringUtils.equalsAny(cateId, ProdCateUtil.getDoubleLineCateIdForArr())) {
            return prodAttrVOList;
        }
        // 不含有业务需求说明字段的不需要处理
        KiteAttr busiRemarkAttr = kiteProdInst.getAttr("200003090");
        if (Objects.isNull(busiRemarkAttr)) {
            return prodAttrVOList;
        }
        // 已有则不需要重复添加
        ProdAttrVO prodAttrVO = prodAttrVOList.stream()
            .filter(AttrVO -> "200003090".equals(AttrVO.getFieldName())).findAny().orElse(null);
        if (Objects.nonNull(prodAttrVO)) {
            return prodAttrVOList;
        }

        prodAttrVOList.add(KiteBeanUtils.transform(busiRemarkAttr, new ProdAttrVO()));

        return prodAttrVOList;
    }

    /**
     * 资料修正操作类型产品属性必填、可编辑配置
     * @author zhang.song
     * @date 2021-05-20 21:27
     * @param sceneInstId
     * @param prodAttrVOListmianl1
     * @return java.util.List<com.iwhalecloud.bss.kite.client.vo.scene.ProdAttrVO>
     */
    public List<ProdAttrVO> prodAttrConfig(String sceneInstId, List<ProdAttrVO> prodAttrVOList, boolean flag) {
        String catagoryId = CuccPosServiceUtils.getCateId(sceneInstId, KiteWebContext.getContext().getCustId());
        String provinceStr = DcPublicCache.getPCode("2021092801","PROVINCE_TYPE");
        // 查询需要联动的字段
        List<DcPublic> dcPublics = DcPublicCache.getByPkey("2021050701", catagoryId);
        if(!ListUtil.isEmpty(dcPublics)) {
            for (DcPublic dcPublic : dcPublics) {
                for (ProdAttrVO prodAttrVO : prodAttrVOList) {
                    if(KiteStringUtils.isEqual(prodAttrVO.getFieldName(), dcPublic.getPcode())) {
                        if(flag) {
                            prodAttrVO.setIsNull(dcPublic.getCodea());
                            prodAttrVO.setIsEdit(dcPublic.getCodeb());
                        } else {
                            prodAttrVO.setIsNull(KeyConsts.IFTRUE_T);
                            prodAttrVO.setIsEdit(KeyConsts.IFTRUE_F);
                        }
                        break;
                    }
                }
            }
            if(KiteStringUtils.isNotEmpty(provinceStr)){
                for (ProdAttrVO prodAttrVO : prodAttrVOList) {
                    if(prodAttrVO.getFieldName().equals("2_0000209")) {
                        String[] valueArr = prodAttrVO.getValue().split(SymbolConsts.COMMA);
                        if(KiteStringUtils.equalsAny(valueArr[0],provinceStr.split(SymbolConsts.COMMA))){
                            for (ProdAttrVO prodAttrVO11 : prodAttrVOList) {
                                if(prodAttrVO11.getFieldName().equals("2_0000211")){
                                    prodAttrVO11.setIsEdit("ST");
                                    break;
                                }
                            }
                        }
                    }else if(prodAttrVO.getFieldName().equals("2_0000105")){
                        String[] valueArr = prodAttrVO.getValue().split(SymbolConsts.COMMA);
                        if(KiteStringUtils.equalsAny(valueArr[0],provinceStr.split(SymbolConsts.COMMA))){
                            for (ProdAttrVO prodAttrVO17 : prodAttrVOList) {
                                if(prodAttrVO17.getFieldName().equals("2_0000117")){
                                    prodAttrVO17.setIsEdit("ST");
                                    break;
                                }
                            }
                        }
                    }
                }
            }
            OperateInstAttrService operateInstAttrService = SpringUtil.getBean(OperateInstAttrService.class);
            List<KiteProdInst> prodInsts = querySceneInstService.listProdInsts(sceneInstId);
            prodInsts.forEach(prodInst -> {
                KiteAttr kiteAttr;
                for (DcPublic dcPublic : dcPublics) {
                    kiteAttr = prodInst.getAttr(dcPublic.getPcode());
                    if(Objects.nonNull(kiteAttr)) {
                        if(flag) {
                            kiteAttr.setIsNull(dcPublic.getCodea());
                            kiteAttr.setIsEdit(dcPublic.getCodeb());
                        } else {
                            kiteAttr.setIsNull(KeyConsts.IFTRUE_T);
                            kiteAttr.setIsEdit(KeyConsts.IFTRUE_F);
                        }
                        operateInstAttrService.setAttrValue(prodInst, kiteAttr.getFieldName(), kiteAttr.getValue(), sceneInstId, null);
                    }
                    if(KiteStringUtils.isNotEmpty(provinceStr)){
                        if(Objects.nonNull(prodInst.getAttr("2_0000220"))&&Objects.nonNull(prodInst.getAttr("2_0000211"))
                            &&KiteStringUtils.equalsAny(prodInst.getAttr("2_0000220").getValue(),provinceStr.split(SymbolConsts.COMMA))){
                            prodInst.getAttr("2_0000211").setIsEdit("ST");
                            operateInstAttrService.setAttrValue(prodInst, "2_0000211", prodInst.getAttr("2_0000211").getValue(), sceneInstId, null);
                        }
                        if(Objects.nonNull(prodInst.getAttr("2_0000107"))
                            &&Objects.nonNull(prodInst.getAttr("2_0000117"))&&KiteStringUtils.equalsAny(prodInst.getAttr("2_0000107").getValue(),provinceStr.split(SymbolConsts.COMMA))){
                            prodInst.getAttr("2_0000117").setIsEdit("ST");
                            operateInstAttrService.setAttrValue(prodInst, "2_0000117", prodInst.getAttr("2_0000117").getValue(), sceneInstId, null);
                        }
                    }
                }
            });
        }
        return prodAttrVOList;
    }

 // 当没有展示的的属性时，将更多的属性直接展示在外面
    private void dealGroupAttrs(List<ProductModuleVO> productModuleVOList) {
        productModuleVOList.forEach(productModuleVO ->{
            productModuleVO.getProdRole().forEach(prodRole -> {
                if (KiteListUtils.isEmpty(prodRole.getProdAttr().getProdAttrList())) {
                    return;
                }
                List<ProdAttrVO> prodAttrList = prodRole.getProdAttr().getProdAttrList().stream().filter(prodAttr ->
                KiteStringUtils.equals(prodAttr.getShowType(), KeyConsts.PROD_ATTR_SHOW_TYPE_D)).collect(Collectors.toList());
                if (KiteListUtils.isEmpty(prodAttrList)) {
                    prodRole.getProdAttr().getProdAttrList().forEach(attr ->{
                        if (KiteStringUtils.equals(attr.getShowType(), KeyConsts.PROD_ATTR_SHOW_TYPE_M)) {
                            attr.setShowType(KeyConsts.PROD_ATTR_SHOW_TYPE_D);
                        }
                    });
                }

            });
        });
    }

}
